package com.qfedu.web;

import com.qfedu.pojo.Account;
import com.qfedu.pojo.History;
import com.qfedu.pojo.User;
import com.qfedu.service.AccountService;
import com.qfedu.service.RecordService;
import com.qfedu.service.impl.AccountServiceImpl;
import com.qfedu.service.impl.RecordServiceImpl;
import org.junit.jupiter.api.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.security.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.List;
@WebServlet("/recordServlet")
public class RecordServlet extends BaseServlet{
    private AccountService accountService = new AccountServiceImpl();

    private RecordService recordService=new RecordServiceImpl();


    protected void queryAllHistory(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
        //获得User
        User user =(User) req.getSession().getAttribute("user");
        Account account = accountService.queryIdcodeByPhone(user.getPhone());
        //获得idcode
        List<History> histories = recordService.queryAllHistory(account.getIdcode());

        req.setAttribute("histories", histories);

        //3、请求转发到/pages/页面
        req.getRequestDispatcher("/pages/history/history.jsp").forward(req,resp);

    }

    protected void queryOneHistory(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
        //获得User
        User user =(User) req.getSession().getAttribute("user");
        Account account = accountService.queryIdcodeByPhone(user.getPhone());
        //获得idcode
        String status=req.getParameter("status");
        List<History> histories = recordService.queryOneHistory(account.getIdcode(),status);

        req.setAttribute("histories", histories);

        //3、请求转发到/pages/页面
        req.getRequestDispatcher("/pages/history/history.jsp").forward(req,resp);

    }


 }
